# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=packaging
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=16.8
pkgrel=3
pkgdesc="Core utilities for Python packages (mingw-w64)"
arch=('any')
url="https://github.com/pypa/packaging"
license=('Apache')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools" "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-pyparsing" "${MINGW_PACKAGE_PREFIX}-python2-pyparsing")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest-runner" "${MINGW_PACKAGE_PREFIX}-python2-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python3-pretend" "${MINGW_PACKAGE_PREFIX}-python2-pretend" 
              "${MINGW_PACKAGE_PREFIX}-python3-coverage" "${MINGW_PACKAGE_PREFIX}-python2-coverage")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/pypa/${_realname}/archive/${pkgver}.tar.gz")
sha256sums=('a48230c947869b53a452bde06889de6ffeeabd252f1426564aaddca3e692f3f6')

prepare() {  
  cd "$srcdir"/  
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}  

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.  
build() {  
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {  
  for pver in {2,3}; do  
    msg "Python ${pver} test for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"  
    ${MINGW_PREFIX}/bin/python${pver} setup.py ptr
  done  
}


package_python3-packaging() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-pyparsing"
           "${MINGW_PACKAGE_PREFIX}-python3-six")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/COPYING"
}

package_python2-packaging() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-pyparsing"
           "${MINGW_PACKAGE_PREFIX}-python2-six")

  cd "${srcdir}/python2-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/COPYING"
}

package_mingw-w64-i686-python2-packaging() {
  package_python2-packaging
}

package_mingw-w64-i686-python3-packaging() {
  package_python3-packaging
}

package_mingw-w64-x86_64-python2-packaging() {
  package_python2-packaging
}

package_mingw-w64-x86_64-python3-packaging() {
  package_python3-packaging
}
